<?xml version="1.0" encoding="UTF-8"?>
<!-- ===============================================================

This stylesheet edits various parameters of Eagle schematic file

-->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="no" indent="yes" doctype-system="eagle.dtd" />

<xsl:strip-space elements="*"/>

<xsl:param name="approved_name">null</xsl:param>
<xsl:param name="approved_date">null</xsl:param>


<xsl:template match="node()|@*">
   <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
   </xsl:copy>
</xsl:template>


<!-- ================================================================
 |
 + ================================================================== -->
<xsl:template match="/">
   <xsl:call-template name="root.messages"/>
   <xsl:apply-templates/>
</xsl:template>

<!-- ================================================================
 |
 + ================================================================== -->
<xsl:template name="root.messages">
   <xsl:message>============================================================</xsl:message>
   <xsl:message> Edit Eagle schematic parameters                            </xsl:message>
   <xsl:message>                                                            </xsl:message>
   <xsl:message> AUTHOR : martin.sveda@saabgroup.com                        </xsl:message>
   <xsl:message> USING  :<xsl:value-of select="system-property('xsl:vendor')"/></xsl:message>
   <xsl:message>============================================================</xsl:message>
   <xsl:message>                                                            </xsl:message>
</xsl:template>

<!-- =================================================================
 |   
 |
 +   ================================================================= -->
<xsl:template match="/eagle/drawing/schematic/attributes/attribute[@name='APPROVED_NAME']">
   <xsl:copy>
      <xsl:attribute name="name"><xsl:value-of select="@name" /></xsl:attribute>
      <xsl:choose>
         <xsl:when test="$approved_name='null'">
            <xsl:attribute name="value"><xsl:value-of select="@value" /></xsl:attribute>
         </xsl:when>
         <xsl:otherwise>
            <xsl:attribute name="value"><xsl:value-of select="$approved_name" /></xsl:attribute>
         </xsl:otherwise>
      </xsl:choose>

      <xsl:apply-templates/>
   </xsl:copy>
</xsl:template>


<!-- =================================================================
 |   
 |
 +   ================================================================= -->
<xsl:template match="/eagle/drawing/schematic/attributes/attribute[@name='APPROVED_DATE']">
   <xsl:copy>
      <xsl:attribute name="name"><xsl:value-of select="@name" /></xsl:attribute>
      <xsl:choose>
         <xsl:when test="$approved_date='null'">
            <xsl:attribute name="value"><xsl:value-of select="@value" /></xsl:attribute>
         </xsl:when>
         <xsl:otherwise>
            <xsl:attribute name="value"><xsl:value-of select="$approved_date"/></xsl:attribute>
         </xsl:otherwise>
      </xsl:choose>

      <xsl:apply-templates/>
   </xsl:copy>
</xsl:template>



<!--
<xsl:template match="@name='APPROVED_NAME'">
  <xsl:attribute name="name">
     <xsl:value-of select="'APPROVED_NAME'"/>
  </xsl:attribute>
  <xsl:attribute name="value">
     <xsl:value-of select="'XXX'"/>
  </xsl:attribute>
</xsl:template>

-->

</xsl:stylesheet> 



<!--

         <xsl:element name="technology">
            <xsl:attribute name="name"><xsl:value-of select="@name" /></xsl:attribute>
            <xsl:attribute name="hash"><xsl:value-of select="concat(attribute[@name='COMPONENT_PACKAGE']/@value, '+', attribute[@name='COMPONENT_VALUE']/@value, '+', @name)" /></xsl:attribute>
            <xsl:apply-templates/>
         </xsl:element>
 
-->